package org.example.develop;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.FilterFunction;
import org.apache.spark.sql.*;
import org.apache.spark.sql.expressions.UserDefinedFunction;
import org.apache.spark.sql.expressions.Window;
import org.apache.spark.sql.expressions.WindowSpec;
import org.apache.spark.sql.types.DataTypes;
import org.example.utils.MysqlUtils_2;

import java.io.IOException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

import static org.apache.spark.sql.functions.*;

/**
 * 创建一个类,主要用来处理tcms的故障数据,根据故障数据做视情为维修和健康评估. 当前类中主要处理的是:模型 1-10
 */
public class JsonProcessorOneToTen {
    public static void main(String[] args) throws AnalysisException, IOException, ParseException {
        // 引入log4j,消除控制台的警告
        Logger.getLogger("org").setLevel(Level.WARN);
        Logger.getLogger("akka").setLevel(Level.WARN);
        SparkConf conf = new SparkConf().setAppName("PantographModelFunction") // 设置应用程序名称
                .setMaster("local[*]") // 设置运行模式，这里是本地模式
                .set("spark.executor.memory", "6g") // 设置executor内存大小
                .set("spark.serializer", "org.apache.spark.serializer.KryoSerializer") // 设置序列化器
                .set("spark.driver.allowMultipleContexts", "true") // 允许多个SparkContext同时存在
                .set("spark.hadoop.validateOutputSpecs", "false") // 禁止输出路径已经存在时抛出异常
                .set("hive.mapred.supports.subdirectories", "true") // 开启Hive支持
                .set("mapreduce.input.fileinputformat.input.dir.recursive", "true") // 开启递归读取文件夹中的文件
                .set("spark.debug.maxToStringFields", "100").set("spark.sql.codegen.wholeStage", "false")
                .set("spark.sql.caseSensitive", "false"); // Spark会自动处理大小写不匹配的情况;
        // 创建SparkContext
        JavaSparkContext sc = new JavaSparkContext(conf);
        SparkSession spark = SparkSession.builder().config(conf).getOrCreate();
        List<String> jsonData = Arrays.asList("[" +
                "{\"s_train_id\": \"HXD1D-1001\",\"idx\": \"1000100011100\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:14\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"phm类别\",\"phm_mc\": \"变流器1充电接触器一卡合故障\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"运用种类\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"故障码\",\"GZLY\":\"故障来源\",\"ZDLB\":\"诊断类别\",\"YFYY\":\"引发原因\"},\n" +
                "{\"s_train_id\": \"HXD1D-1001\",\"idx\": \"1000100011101\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:16\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"phm类别\",\"phm_mc\": \"变流器1充电接触器二卡合故障\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"运用种类\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"故障码\",\"GZLY\":\"故障来源\",\"ZDLB\":\"诊断类别\",\"YFYY\":\"引发原因\"},\n" +
                "{\"s_train_id\": \"HXD1D-1001\",\"idx\": \"1000100011102\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:17\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"phm类别\",\"phm_mc\": \"变流器1充电接触器三卡合故障\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1001\",\"idx\": \"1000100011103\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:18\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"phm类别\",\"phm_mc\": \"变流器2短接接触器一卡合故障\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1001\",\"idx\": \"1000100011104\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:20\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"phm类别\",\"phm_mc\": \"变流器2短接接触器二卡合故障\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1001\",\"idx\": \"1000100011105\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:21\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"phm类别\",\"phm_mc\": \"变流器2短接接触器三卡合故障\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1001\",\"idx\": \"1000100011106\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:21\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"phm类别\",\"phm_mc\": \"变流器1短接接触器三卡合故障\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1001\",\"idx\": \"1000100011107\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:21\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"phm类别\",\"phm_mc\": \"变流器1短接接触器一卡合故障\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1001\",\"idx\": \"1000100011108\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:21\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"phm类别\",\"phm_mc\": \"变流器1短接接触器二卡合故障\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1001\",\"idx\": \"1000100011109\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:21\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"phm类别\",\"phm_mc\": \"变流器2短接接触器一卡合故障\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1001\",\"idx\": \"1000100011110\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:21\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"phm类别\",\"phm_mc\": \"变流器2充电接触器二卡合故障\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1001\",\"idx\": \"1000100011111\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:21\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"phm类别\",\"phm_mc\": \"变流器2充电接触器三卡合故障\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1002\",\"idx\": \"2000100011111\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:22\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"phm类别\",\"phm_mc\": \"变流器2充电接触器二卡分故障\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1002\",\"idx\": \"2000100011102\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:16\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"phm类别\",\"phm_mc\": \"变流器2短接接触器三卡分故障\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1003\",\"idx\": \"3000100011101\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:20\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"变流器元件故障报警\",\"phm_mc\": \"变流器1ACC元件总故障\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1003\",\"idx\": \"3000100011102\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:25\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"变流器元件故障报警\",\"phm_mc\": \"变流器1ACC的U相下管故障\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1003\",\"idx\": \"3000100011103\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:28\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"变流器元件故障报警\",\"phm_mc\": \"变流器1ACC的V相上管故障\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1003\",\"idx\": \"3000100011104\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:22\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"变流器元件故障报警\",\"phm_mc\": \"变流器1ACC的U相上管故障\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1003\",\"idx\": \"3000100011105\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:21\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"变流器元件故障报警\",\"phm_mc\": \"变流器1ACC的W相上管故障\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1003\",\"idx\": \"3000100011106\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:19\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"变流器元件故障报警\",\"phm_mc\": \"变流器1M3斩波管故障\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1003\",\"idx\": \"3000100011106\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:19\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"变流器元件故障报警\",\"phm_mc\": \"变流器2M2斩波管故障\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1004\",\"idx\": \"3000100011107\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:19\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"TCU通讯故障\",\"phm_mc\": \"TCU1_MCC1通讯中断\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1004\",\"idx\": \"3000100011108\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:19\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"TCU通讯故障\",\"phm_mc\": \"TCU1_MCC2通讯中断\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1004\",\"idx\": \"3000100011109\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:19\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"TCU通讯故障\",\"phm_mc\": \"TCU1_MCC3通讯中断\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1066\",\"idx\": \"30001000111020\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-18 10:00:19\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"模块过热\",\"phm_mc\": \"变流器1第三重模块过热\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1066\",\"idx\": \"30001000111021\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-18 10:00:20\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"模块过热\",\"phm_mc\": \"变流器1第二重模块过热\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1066\",\"idx\": \"30001000111022\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:21\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"模块过热\",\"phm_mc\": \"变流器1第一重模块过热\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1066\",\"idx\": \"30001000111023\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:25\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"模块过热\",\"phm_mc\": \"辅逆1模块过热\",\"phm_bjwz\": \"1\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1077\",\"idx\": \"30001000111024\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:19\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"模块过热\",\"phm_mc\": \"变流器2第一重模块过热\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1077\",\"idx\": \"30001000111025\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:39\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"模块过热\",\"phm_mc\": \"辅逆2模块过热\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1005\",\"idx\": \"30001000111010\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:19\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"TCU通讯故障\",\"phm_mc\": \"TCU2_MCC1通讯中断\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1005\",\"idx\": \"30001000111011\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:19\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"TCU通讯故障\",\"phm_mc\": \"TCU2_MCC1通讯中断\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1005\",\"idx\": \"30001000111012\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:19\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"TCU通讯故障\",\"phm_mc\": \"TCU2_MCC2通讯中断\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1005\",\"idx\": \"30001000111013\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:19\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"TCU通讯故障\",\"phm_mc\": \"TCU2_MCC3通讯中断\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1005\",\"idx\": \"30001000111014\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:19\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"TCU通讯故障\",\"phm_mc\": \"TCU2_LCC通讯中断\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"},\n" +
                "{\"s_train_id\": \"HXD1D-1005\",\"idx\": \"10001000111013\",\"cx\": \"HXD1D\",\"source\": \"tcms\",\"gzkssj_up\": \"2023-03-17 10:00:18\",\"ssxt\": \"牵引系统\",\"xtbm\": \"系统编码\",\"xtpjm\": \"故障系统码2（PJ码）\",\"ssbj\": \"牵引变流器\",\"bjbm\": \"部件编码\",\"bjpjm\": \"PJ00003\",\"gzdm_wm\": \"故障代码\",\"gzmc\": \"故障名称\",\"phm_lb\": \"变流器元件故障报警\",\"phm_mc\": \"变流器2M2斩波管故障\",\"phm_bjwz\": \"2\",\"zj_ms\": \"珠玑-描述\",\"zj_fa\": \"珠玑-失修方法\",\"pjxlh\": \"配件序列号\",\"pjdjm\": \"配件单件码\",\"lj\": \"路局\",\"ljjc\": \"路局简称\",\"lj_id\": \"路局码\",\"psd\": \"配属段\",\"psdjc\": \"配属段简称\",\"psd_id\": \"配属段代码\",\"cksj\": \"2023-03-20 12:10:35\",\"JCDLLXMC\":\"动力类型\",\"RC\":\"修程\",\"YYZL\":\"-\",\"ZZC\":\"生产厂家\",\"ZZRQ\":\"制造日期\",\"LJZXGL\":\"累计走行\",\"GZM\":\"-\",\"GZLY\":\"TCMS\",\"ZDLB\":\"-\",\"YFYY\":\"-\"}\n" +
                "]"
        );


        // 将json字符串转换成JavaRDD对象
        JavaRDD<String> jsonRDD = sc.parallelize(jsonData);
        // 最终返回健康评估结果
        unionHealthAssessment(spark, jsonRDD);
        spark.stop();
    }


    /***
     *  定义一个方法,调用此方法,会返回健康评估的结果,返回值是一个DataSet.
     * @param spark
     * @param jsonRDD 传入当前批次的tcms的实时数据
     * @return 健康评估最终结果
     * @throws AnalysisException
     * @throws IOException
     * @throws ParseException
     */
    public static Dataset<Row> unionHealthAssessment(SparkSession spark, JavaRDD<String> jsonRDD) throws AnalysisException, IOException, ParseException {
        // 处理陈浩传过来的tcms实时数据,拉去到后续作业中需要的字段. 这里是将 tcms 实时数据 left join 模型详情表,拉去到的宽表.后续所有的操作都是在这个数据集中进行后续操作.
        Dataset<TcmsRealDataJoinMxxq> tcmsJoinMxxqDs = jsonRddToDataset(spark, jsonRDD);
        // 拉取到 `t_phm_sqwx` 视情维修表中的当前躺中的历史数据.
        Dataset<Row> tPhmSqwxLocalHistory = MysqlUtils_2.readMysqlTableDs(spark, "t_phm_sqwx")
                .filter(col("hkzt").equalTo("0").and(col("bjpjm").equalTo("PJ00003")).and(col("cx").equalTo("HXD1D")));
        // 拉取到 `ads_phm_fault` 表中的当前躺的历史数据,用于后续的 健康评估.
        Dataset<Row> adsPhmFaultLocalHistory = MysqlUtils_2.readMysqlTableDs(spark, "ads_phm_fault")
                .filter(expr("S_HKZT = '0' and S_FAULT_BW_CODE2 = 'PJ00003' and s_train_type_code = 'HXD1D'"));

        List<DatasetContainer> list = new ArrayList<>();
        list.add(processFaultType1(spark, tcmsJoinMxxqDs, tPhmSqwxLocalHistory, adsPhmFaultLocalHistory));
        list.add(processFaultType22(spark, tcmsJoinMxxqDs, tPhmSqwxLocalHistory, adsPhmFaultLocalHistory));
        DatasetContainer datasetContainer = DatasetContainer.unionDatasets2(list);
        datasetContainer.getDataset1().show(false);
        datasetContainer.getDataset2().show(false);
        datasetContainer.getDataset3().show(false);


//        MysqlUtils_2.writeDataToMysqlTable(datasetContainer.getDataset1(), "ads_phm_fault", SaveMode.Append);
//        MysqlUtils_2.upsertDatasetToMySQL(datasetContainer.getDataset2(), "t_phm_sqwx");
        return datasetContainer.getDataset3();
    }

    /***
     * 22、牵引变流器模块过热故障视情维修模型 视情维修和健康评估结果
     * @param spark
     * @param inputData
     * @param tPhmSqwxLocalHistory
     * @param adsPhmFaultLocalHistory
     * @return
     * @throws IOException
     * @throws ParseException
     */
    public static DatasetContainer processFaultType22(SparkSession spark, Dataset<TcmsRealDataJoinMxxq> inputData, Dataset<Row> tPhmSqwxLocalHistory, Dataset<Row> adsPhmFaultLocalHistory) throws IOException, ParseException {
        Dataset<TcmsRealDataJoinMxxq> tcmsRealDataDS = inputData.filter((FilterFunction<TcmsRealDataJoinMxxq>) tcmsRealDataJoinMxxq -> tcmsRealDataJoinMxxq.getMX_ID().equals("10022"));

        // t_phm_sqwx 这张表中的历史数据字段.
        //s_train_id,cx,lj,ljjc,ljm,psd,psdjc,psddm,ssxt,xtpjm,ssbj,bjpjm,bjwz,bjxlh,bjdjm,xfzt,htzt,hkzt,status,czjy,mx,mxmc,mxms,dllx,rc,yyzl,sccj,zzrq,ljzx,gzm,gzly,zdlb,yfyy,hkzbjy,hkjxjy,cksj,mx_id
        Dataset<Row> localHistorySqwxDS = selectColumnsTPhmSqwxOut(tPhmSqwxLocalHistory
                .filter(col("mx").equalTo("模块过热")))
                .withColumn("cksj", expr("substring_index(id, '-', -1)")) // 从 id 字段中截取到 cksj 出库时间这个字段的值,这里是经过格式化后的数据,eg: 20230320121035
                .withColumn("mx_id", expr("substring_index(substring_index(id, '-', 4), '-', -1)")) // 获取到 mx_id 这个字段的值,也就是: 1066 这种
                .drop("id").drop("create_time"); // 这里需要将实时数据 开窗聚合的结果 添加这两个字段. id、create_time
        // 当前批次中 tcms中实时报警数据字段,选中待插入到 t_phm_sqwx 这个表中的关键字段
        //s_train_id,cx,lj,ljjc,ljm,psd,psdjc,psddm,ssxt,xtpjm,ssbj,bjpjm,bjwz,bjxlh,bjdjm,xfzt,htzt,hkzt,status,czjy,mx,mxmc,mxms,dllx,rc,yyzl,sccj,zzrq,ljzx,gzm,gzly,zdlb,yfyy,hkzbjy,hkjxjy,cksj,mx_id
        Dataset<Row> tcmsRealDataSqwxDS = selectColumnsTPhmSqwxIn(tcmsRealDataDS).select("s_train_id", "cx", "lj", "ljjc", "ljm", "psd", "psdjc", "psddm", "ssxt", "xtpjm", "ssbj", "bjpjm", "bjwz", "bjxlh", "bjdjm", "xfzt", "htzt", "hkzt", "status", "czjy", "mx", "mxmc", "mxms", "dllx", "rc", "yyzl", "sccj", "zzrq", "ljzx", "gzm", "gzly", "zdlb", "yfyy", "hkzbjy", "hkjxjy", "cksj", "mx_id");
        /*
            处理后的 视情维修结果 添加如下字段,再灌入到 `t_phm_sqwx` 这个表中
                .withColumn("id", concat_ws("-", col("s_train_id"), col("mx_id"), col("cksj")))
                .withColumn("create_time", current_timestamp())
                .withColumn("fssj", current_timestamp());
         */

        // 从历史数据中拉取当前元件故障数据中的最后10秒的数据,判断是否存在 故障 组合情况.
        Dataset<Row> adsPhmFaultLocalHistoryDS = adsPhmFaultLocalHistory.filter(col("mxjg").equalTo("模块过热")).select("s_train_id", "s_fault_id", "mx_id", "s_train_name", "s_train_type_code", "s_fault_source", "s_fault_time", "s_fault_sys", "s_fault_sys_code1", "s_fault_sys_code2", "s_fault_bw", "s_fault_bw_code1", "s_fault_bw_code2", "s_fault_code", "s_fault_name", "phm_lb", "mxjg", "phm_gzmc", "phm_bjwz", "zj_ms", "zj_fa", "pjxlh", "pjdjm", "s_htzt", "s_hkzt", "s_xfzt");
        Dataset<Row> tcmsRealDataAdsPhmFaultDS = selectColumnsAdsPhmFault(tcmsRealDataDS);
        Dataset<Row> adsPhmFaultAllDS = null;
        if (adsPhmFaultLocalHistoryDS.count() > 0) {
            // 如果当前元件故障存在历史数据,则拉取到最后的10秒的数据,并判断是否存在故障名称的关联关系.
            String lastBatchMaxFaultTimeStr = adsPhmFaultLocalHistoryDS.agg(max("s_fault_time")).collectAsList().get(0).getString(0); //获取上一个批次中当前元件的 最大的 s_fault_time
            // 定义时间格式
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            // 使用自定义时间格式将字符串形式的时间转换为 Timestamp 类型
            Timestamp maxTime = new Timestamp(dateFormat.parse(lastBatchMaxFaultTimeStr).getTime());
            // 将最大时间转换为 Unix 时间戳（以毫秒为单位），然后减去 10 秒
            long maxTimeUnix = maxTime.getTime() - (10 * 1000);
            // 将 Unix 时间戳（以毫秒为单位）转换回 Timestamp 类型
            Timestamp maxTimeMinus10Seconds = new Timestamp(maxTimeUnix);
            // 使用 expr() 创建一个新的筛选条件，选择 s_fault_time 在最大时间的 10秒前的数据.
            Column filterCondition = expr("s_fault_time >= '" + dateFormat.format(maxTimeMinus10Seconds) + "'");
            // 获取到上个批次最后10秒的数据
            Dataset<Row> lastBatch10SDs = adsPhmFaultLocalHistoryDS.filter(filterCondition);
            adsPhmFaultAllDS = lastBatch10SDs.union(tcmsRealDataAdsPhmFaultDS);
        } else {
            adsPhmFaultAllDS = tcmsRealDataAdsPhmFaultDS;
        }
        // 定义窗口函数,这里不需要 s_fault_id , phm_gzmc , s_fault_time  需要取到最小值.
        WindowSpec windowSpec = Window.partitionBy("s_train_id", "mx_id", "s_train_name", "s_train_type_code", "s_fault_source", "s_fault_sys", "s_fault_sys_code1", "s_fault_sys_code2", "s_fault_bw", "s_fault_bw_code1", "s_fault_bw_code2", "s_fault_code", "s_fault_name", "phm_lb", "mxjg", "phm_bjwz", "zj_ms", "zj_fa", "pjxlh", "pjdjm", "s_htzt", "s_hkzt", "s_xfzt").orderBy("s_fault_time");
        // 计算每一行与上一行的时间差（单位：秒）
        Dataset<Row> allProcessRealFaultsSecondDiff = adsPhmFaultAllDS.withColumn(
                "time_diff",
                unix_timestamp(col("s_fault_time")).minus(lag(unix_timestamp(col("s_fault_time")), 1).over(windowSpec))
        );
        // 判断时间差是否大于等于10秒，如果是，则表示新的会话开始
        Dataset<Row> allProcessRealFaultsSessionFlag = allProcessRealFaultsSecondDiff.withColumn(
                "is_new_session",
                when(col("time_diff").isNull().or(col("time_diff").geq(10)), 1).otherwise(0)
        );
        // 计算会话 ID
        Dataset<Row> allProcessRealFaultsSessionId = allProcessRealFaultsSessionFlag.withColumn(
                "session_id",
                sum("is_new_session").over(windowSpec)
        );
        UserDefinedFunction generateUUID = udf((input) -> UUID.randomUUID().toString().substring(0, 16), DataTypes.StringType);
        // 注册 UDF
        spark.udf().register("generateUUID", generateUUID);
        Dataset<Row> finalInsertAdsPhmFaultAddMxmcDS = allProcessRealFaultsSessionId.groupBy("s_train_id", "mx_id", "s_train_name", "s_train_type_code", "s_fault_source", "s_fault_sys", "s_fault_sys_code1", "s_fault_sys_code2", "s_fault_bw", "s_fault_bw_code1", "s_fault_bw_code2", "s_fault_code", "s_fault_name", "phm_lb", "mxjg", "phm_bjwz", "zj_ms", "zj_fa", "pjxlh", "pjdjm", "s_htzt", "s_hkzt", "s_xfzt", "session_id")
                .agg(
                        collect_set(col("phm_gzmc")).alias("phm_gzmc"),
                        min(col("s_fault_time")).alias("s_fault_time")
                )
                .withColumn("mxmc", when(size(col("phm_gzmc")).geq(2), lit("所有模块均过热")) // 当 element_nums 大于等于 2 时 "所有模块均过热"
                        .otherwise(regexp_replace(concat_ws("", col("phm_gzmc")), "变流器[1-2]", ""))
                )
                .withColumn("phm_gzmc", concat_ws(",", col("phm_gzmc")))
                .withColumn("s_fault_id", callUDF("generateUUID", current_timestamp()));
        Dataset<Row> finalInsertAdsPhmFaultDS = finalInsertAdsPhmFaultAddMxmcDS.select("s_train_id", "s_fault_id", "mx_id", "s_train_name", "s_train_type_code", "s_fault_source", "s_fault_time", "s_fault_sys", "s_fault_sys_code1", "s_fault_sys_code2", "s_fault_bw", "s_fault_bw_code1", "s_fault_bw_code2", "s_fault_code", "s_fault_name", "phm_lb", "mxjg", "phm_gzmc", "phm_bjwz", "zj_ms", "zj_fa", "pjxlh", "pjdjm", "s_htzt", "s_hkzt", "s_xfzt");
        // 最终插入到 ads_phm_fault 这个表中的数据
        finalInsertAdsPhmFaultDS.show(false);
        return new DatasetContainer(finalInsertAdsPhmFaultDS, null, null);
    }

    /***
     * 处理HXD1D 模型一:牵引变流器接触器卡合故障视情维修模型的事情维修和健康评估功能. 故障详情入 `ads_phm_fault`表 健康评估结果入 `t_phm_sqwx`表中,最终的健康评估需要 union返回.
     * @param spark
     * @param inputData jsonRddToDataset方法处理的结果
     * @param tPhmSqwxLocalHistory `t_phm_sqwx`当前趟中的历史数据
     * @param adsPhmFaultLocalHistory `ads_phm_fault` 当前趟中的历史数据.
     * @return
     * @throws IOException
     */
    public static DatasetContainer processFaultType1(SparkSession spark, Dataset<TcmsRealDataJoinMxxq> inputData, Dataset<Row> tPhmSqwxLocalHistory, Dataset<Row> adsPhmFaultLocalHistory) throws IOException {
        DatasetContainer mx1Res = processFaultCommon(spark, inputData, tPhmSqwxLocalHistory, adsPhmFaultLocalHistory, "10001", "接触器卡合故障");
        // 健康评估处理逻辑:这里根据每个车型、车号、每趟、每个位置上的数据进行判定,判定规则: 当 phm_gzmc
        // 创建 自定义NumberExtractor类,根据`bjwz`和`phm_gzmc`实现对当前DataSet内的的phm_gzmc中文数字进行处理操作.
        NumberExtractor extractor = new NumberExtractor(spark);
        // 经过轴信息返回最终健康评估结果.
        Dataset<Row> rowDataset = extractor.applyUDF((Dataset<Row>) mx1Res.getDataset3());
        Dataset<Row> rowDataset1 = selectColumnsReturnHealthAssessment(rowDataset.withColumn("pgjg", expr("case when extracted_numbers = '1,2,3' or extracted_numbers = '4,5,6' then 'C' else 'B' end"))
                .withColumnRenamed("phm_gzmc", "jgms")
                .withColumnRenamed("extracted_numbers", "zxx"));
        return new DatasetContainer(mx1Res.getDataset1(), mx1Res.getDataset2(), rowDataset1);
    }

    /***
     *
     * @param spark
     * @param inputData 当前tcms的实时数据 left join 模型详情表的最终结果.也就是当前的DataSet中包含当前批次的所有故障数据.每个方法只需要处理自己的部分就好.
     * @param tPhmSqwxLocalHistory 读取 mysql  `t_phm_sqwx` 视情维修表中的当前趟中的历史数据.
     * @param adsPhmFaultLocalHistory 读取 mysql  `ads_phm_fault` 故障详情表中的当前趟中的历史数据.
     */
    public static DatasetContainer processFaultCommon(SparkSession spark, Dataset<TcmsRealDataJoinMxxq> inputData, Dataset<Row> tPhmSqwxLocalHistory, Dataset<Row> adsPhmFaultLocalHistory, String mx_id, String mxmc) throws IOException {
        Dataset<TcmsRealDataJoinMxxq> tcmsRealDataJoinMxxqDataset = inputData.filter((FilterFunction<TcmsRealDataJoinMxxq>) tcmsRealDataJoinMxxq -> tcmsRealDataJoinMxxq.getMX_ID().equals(mx_id));
        // `t_phm_sqwx` 表中当前趟中指定的 模型名称 待处理历史数据 ......
        Dataset<Row> localHistorySqwxDS = selectColumnsTPhmSqwxOut(tPhmSqwxLocalHistory
                .filter(col("mx").equalTo(mxmc)))
                .withColumn("cksj", expr("substring_index(id, '-', -1)"))
                .withColumn("mx_id", expr("substring_index(substring_index(id, '-', 4), '-', -1)"))
                .drop("id").drop("create_time")
                .select("s_train_id", "cx", "lj", "ljjc", "ljm", "psd", "psdjc", "psddm", "ssxt", "xtpjm", "ssbj", "bjpjm", "bjwz", "bjxlh", "bjdjm", "xfzt", "htzt", "hkzt", "status", "czjy", "mx", "mxmc", "mxms", "cksj", "mx_id", "dllx", "rc", "yyzl", "sccj", "zzrq", "ljzx", "gzm", "gzly", "zdlb", "yfyy", "hkzbjy", "hkjxjy");
//        System.out.println("========== 当前模型中所有的实时数据..........");
//        tcmsRealDataJoinMxxqDataset.show(false);
        // ======================================================================================== 入 ads_phm_fault 逻辑 =================================================
        // 对于单一故障,没有组合关系的报警信息,来一条就可以入一条数据到 `ads_phm_fault`中.
        //System.out.println("入 ads_phm_fault 表中的数据..........");
        Dataset<Row> adsPhmFault = selectColumnsAdsPhmFault(tcmsRealDataJoinMxxqDataset);
        //MysqlUtils_2.writeDataToMysqlTable(adsPhmFault, "ads_phm_fault", SaveMode.Append);
        // ======================================================================================== 入 ads_phm_fault 完成 =================================================

        // 入 t_phm_sqwx 表中的逻辑: 当前tcms实时数据 + 当前躺中 t_phm_sqwx 表中的历史数据,聚合操作,并最终更新写入到 t_phm_sqwx.聚合的粒度:每个车型、车号、位置、模型、每趟 聚合成一列.
        // TODO 2023-04-07: 这里需要将 CZJY、GZM、HKZBJY、HKJXJY 这几个字段也要聚合成一行.
        Dataset<Row> tcmsRealSqwxInsertDS = selectColumnsTPhmSqwxIn(tcmsRealDataJoinMxxqDataset);
        Dataset<Row> sqwxInsertFinalDS = null;
        if (localHistorySqwxDS.count() > 0) {
            // 如果当前批次拉取到的当前趟的数据集不是空的,则需要将视情维修历史 + tcms 实时数据 union,再聚合
            sqwxInsertFinalDS = localHistorySqwxDS.union(tcmsRealSqwxInsertDS)
                    .groupBy("s_train_id", "cx", "lj", "ljjc", "ljm", "psd", "psdjc", "psddm", "ssxt", "xtpjm", "ssbj", "bjpjm", "bjwz", "bjxlh", "bjdjm", "xfzt", "htzt", "hkzt", "status", "mx", "cksj", "mx_id", "dllx", "rc", "yyzl", "sccj", "zzrq", "ljzx", "gzly", "zdlb", "yfyy")
                    .agg(
                            concat_ws(",", collect_set(col("mxmc"))).alias("mxmc"),
                            concat_ws(",", collect_set(col("mxms"))).alias("mxms"),
                            concat_ws(",", collect_set(col("czjy"))).alias("czjy"),
                            concat_ws(",", collect_set(col("gzm"))).alias("gzm"),
                            concat_ws(",", collect_set(col("hkzbjy"))).alias("hkzbjy"),
                            concat_ws(",", collect_set(col("hkjxjy"))).alias("hkjxjy")
                    )
                    .withColumn("id", concat_ws("-", col("s_train_id"), col("mx_id"), col("cksj")))
                    .withColumn("create_time", current_timestamp())
                    .withColumn("fssj", current_timestamp());
        } else {
            sqwxInsertFinalDS = tcmsRealSqwxInsertDS
                    .groupBy("s_train_id", "cx", "lj", "ljjc", "ljm", "psd", "psdjc", "psddm", "ssxt", "xtpjm", "ssbj", "bjpjm", "bjwz", "bjxlh", "bjdjm", "xfzt", "htzt", "hkzt", "status", "mx", "cksj", "mx_id", "dllx", "rc", "yyzl", "sccj", "zzrq", "ljzx", "gzly", "zdlb", "yfyy")
                    .agg(
                            concat_ws(",", collect_set(col("mxmc"))).alias("mxmc"),
                            concat_ws(",", collect_set(col("mxms"))).alias("mxms"),
                            concat_ws(",", collect_set(col("czjy"))).alias("czjy"),
                            concat_ws(",", collect_set(col("gzm"))).alias("gzm"),
                            concat_ws(",", collect_set(col("hkzbjy"))).alias("hkzbjy"),
                            concat_ws(",", collect_set(col("hkjxjy"))).alias("hkjxjy")
                    )
                    .withColumn("id", concat_ws("-", col("s_train_id"), col("bjwz"), col("mx_id"), col("cksj")))
                    .withColumn("create_time", current_timestamp())
                    .withColumn("fssj", current_timestamp());
        }
        //MysqlUtils_2.upsertDatasetToMySQL(selectColumnsTPhmSqwxOut(sqwxInsertFinalDS), "t_phm_sqwx");

        // 健康评估需要的数据: ads_phm_fault 当前趟的历史数据 + 当前批次的 tcms 的 ads_phm_fault 数据 进行 union + 聚合的结果.
        Dataset<Row> tcmsAdsPhmFaultDS = tcmsRealDataJoinMxxqDataset.select(col("s_train_id"), col("bjpjm"), col("phm_bjwz").as("bjwz"),
                col("mx_id").as("mxmc"), col("xxms"));
        Dataset<Row> rowDatasetHistoryDS = adsPhmFaultLocalHistory.select(col("s_train_id"), col("S_FAULT_BW_CODE2").as("bjpjm"), col("phm_bjwz").as("bjwz"),
                split(col("mx_id"), "-").getItem(3).as("mxmc"), col("phm_gzmc").as("xxms")).filter(col("mxmc").equalTo(mx_id));
        Dataset<Row> healthDs = null;
        if (rowDatasetHistoryDS.count() > 0) {
            healthDs = tcmsAdsPhmFaultDS.union(rowDatasetHistoryDS)
                    .groupBy("s_train_id", "bjpjm", "bjwz", "mxmc")
                    .agg(concat_ws(",", collect_set(col("xxms"))).alias("phm_gzmc"));
        } else {
            healthDs = tcmsAdsPhmFaultDS
                    .groupBy("s_train_id", "bjpjm", "bjwz", "mxmc")
                    .agg(concat_ws(",", collect_set(col("xxms"))).alias("phm_gzmc"));
        }
//        healthDs.show(false);
        // Done 这里给每个模型返回的健康评估结果,需要加一个过滤条件,从而返回给每个模型的健康评估结果是正确的.
        return new DatasetContainer(adsPhmFault, selectColumnsTPhmSqwxOut(sqwxInsertFinalDS), healthDs);
    }

    public static Dataset<Row> selectColumnsAdsPhmFault(Dataset<TcmsRealDataJoinMxxq> inputDS) {
        return inputDS.select(col("s_train_id"), col("idx").as("s_fault_id"), concat_ws("-", col("s_train_id"), col("phm_bjwz"), col("mx_id"), date_format(col("cksj"), "yyyyMMddHHmmss")).as("mx_id"), col("s_train_id").as("s_train_name"),
                col("cx").as("s_train_type_code"), col("source").as("s_fault_source"), col("gzkssj_up").as("s_fault_time"), col("ssxt").as("s_fault_sys"),
                col("xtbm").as("s_fault_sys_code1"), col("xtpjm").as("s_fault_sys_code2"), col("ssbj").as("s_fault_bw"), col("bjbm").as("s_fault_bw_code1"),
                col("bjpjm").as("s_fault_bw_code2"), col("gzdm_wm").as("s_fault_code"), col("gzmc").as("s_fault_name"), col("phm_lb"), col("mxjg"), col("phm_mc").as("phm_gzmc"),
                col("phm_bjwz"), col("zj_ms"), col("zj_fa"), col("pjxlh"), col("pjdjm"), lit("0").as("s_htzt"), lit("0").as("s_hkzt"), lit("0").as("s_xfzt"));
    }

    /***
     * 拉取 `ads_phm_fault`表中当前趟的历史数据,选取字段.
     * @param inputDS
     * @return
     */
    public static Dataset<Row> selectColumnsAdsPhmFaultReadHistory(Dataset<Row> inputDS) {
        return inputDS.select(col("s_train_id"), col("s_fault_id"), split(col("mx_id"), "-").getItem(3).as("mx_id"), split(col("mx_id"), "-").getItem(4).as("cksj"),
                col("s_train_name"), col("s_train_type_code"), col("s_fault_source"), col("s_fault_time"), col("s_fault_sys"),
                col("s_fault_sys_code1"), col("s_fault_sys_code2"), col("s_fault_bw"), col("s_fault_bw_code1"),
                col("s_fault_bw_code2"), col("s_fault_code"), col("s_fault_name"), col("phm_lb"), col("mxjg"), col("phm_gzmc"),
                col("phm_bjwz"), col("zj_ms"), col("zj_fa"), col("pjxlh"), col("pjdjm"), col("s_htzt"), col("s_hkzt"), col("s_xfzt"));
    }

    public static Dataset<Row> selectColumnsAdsPhmFaultYjgz(Dataset<Row> inputDS) {
        return inputDS.select(col("s_train_id"), col("idx").as("s_fault_id"), concat_ws("-", col("s_train_id"), col("phm_bjwz"), col("mx_id"), date_format(col("cksj"), "yyyyMMddHHmmss")).as("mx_id"), col("s_train_id").as("s_train_name"),
                col("cx").as("s_train_type_code"), col("source").as("s_fault_source"), col("gzkssj_up").as("s_fault_time"), col("ssxt").as("s_fault_sys"),
                col("xtbm").as("s_fault_sys_code1"), col("xtpjm").as("s_fault_sys_code2"), col("ssbj").as("s_fault_bw"), col("bjbm").as("s_fault_bw_code1"),
                col("bjpjm").as("s_fault_bw_code2"), col("gzdm_wm").as("s_fault_code"), col("gzmc").as("s_fault_name"), col("phm_lb"), col("mxjg"), col("phm_mc").as("phm_gzmc"),
                col("phm_bjwz"), col("zj_ms"), col("zj_fa"), col("pjxlh"), col("pjdjm"), lit("0").as("s_htzt"), lit("0").as("s_hkzt"), lit("0").as("s_xfzt"));
    }

    /***
     * 从 tcms 实时数据 + 模型详情 join的宽表中 拉取 `t_phm_sqwx` 表中需要聚合的字段.
     * @param inputDS
     * @return
     */
    public static Dataset<Row> selectColumnsTPhmSqwxIn(Dataset<TcmsRealDataJoinMxxq> inputDS) {
        return inputDS.select(col("s_train_id"), col("cx"), col("lj"), col("ljjc"), col("lj_id").as("ljm"), col("psd"), col("psdjc"),
                col("psd_id").as("psddm"), col("ssxt"), col("xtpjm"), col("ssbj"), col("bjpjm"), col("phm_bjwz").as("bjwz"), col("pjxlh").as("bjxlh"),
                col("pjdjm").as("bjdjm"), lit("0").as("xfzt"), lit("0").as("htzt"), lit("0").as("hkzt"), lit("1").as("status"),
                col("czjy"), col("mxjg").as("mx"), col("jgms").as("mxmc"), col("xxms").as("mxms"), date_format(col("cksj"), "yyyyMMddHHmmss").as("cksj"), col("mx_id"),
                col("jcdllxmc").as("dllx"), col("rc"), lit("-").as("yyzl"), col("zzc").as("sccj"), col("zzrq"), col("ljzxgl").as("ljzx"), lit("-").as("gzm"), lit("TCMS").as("gzly"), lit("-").as("zdlb"), lit("-").as("yfyy"), col("zbjy").as("hkzbjy"), col("JXJY").as("hkjxjy"));
    }

    /***
     * 从指定的 DataSet 中拉取到 入 `t_phm_sqwx`表中的字段
     * @param writeDs
     * @return
     */
    public static Dataset<Row> selectColumnsTPhmSqwxOut(Dataset<Row> writeDs) {
        return writeDs.select(col("id"), col("s_train_id"), col("cx"), col("lj"), col("ljjc"), col("ljm"), col("psd"), col("psdjc"),
                col("psddm"), col("ssxt"), col("xtpjm"), col("ssbj"), col("bjpjm"), col("bjwz"), col("bjxlh"),
                col("bjdjm"), col("xfzt"), col("htzt"), col("hkzt"), col("create_time"), col("status"),
                col("czjy"), col("mx"), col("mxmc"), col("mxms"), col("dllx"), col("rc"), col("yyzl"), col("sccj"), col("zzrq"), col("ljzx"), col("gzm"), col("gzly"), col("zdlb"), col("yfyy"), col("hkzbjy"), col("hkjxjy"));
    }

    public static Dataset<Row> selectColumnsReturnHealthAssessment(Dataset<Row> healthAssessmentResDS) {
        return healthAssessmentResDS.select("s_train_id", "bjpjm", "bjwz", "mxmc", "pgjg", "zxx", "jgms");
    }

    /***
     * 传入当前批次中 tcms实时报警数据: JavaRDD<String> jsonRDD ,返回一个 DataSet<TcmsRealData> 的数据集.
     * @param spark
     * @param jsonRDD
     * @return 当前数据集中包含了 `ads_phm_fault`和 `t_phm_sqwx` 表中所有的字段.
     */
    public static Dataset<TcmsRealDataJoinMxxq> jsonRddToDataset(SparkSession spark, JavaRDD<String> jsonRDD) throws IOException {
        Dataset<Row> jsonData = spark.read().json(jsonRDD);
        // 将 Dataset<Row> 转换为 Dataset<tcmsRealData>,里面存放的是 `tcms` 实时数据.
        Dataset<TcmsRealData> tcmsRealDataDS = jsonData.as(Encoders.bean(TcmsRealData.class));
        // 这里进行数据过滤:只要 cx = `HXD1D` 并且 phm_lb != '-'
        Dataset<TcmsRealData> hxd1DTcmsRealDataDS = tcmsRealDataDS.filter(
                (FilterFunction<TcmsRealData>) tcmsRealData -> tcmsRealData.getCx().equals("HXD1D") && !tcmsRealData.getPhm_lb().equals("-")
        );
        //读取 模型详情`t_phm_mxxq`字典,拉去模型相关的字段. 这里两张表进行关联.
        Dataset<PhmMxxq> mxxqDS = MysqlUtils_2.readMysqlTableDs(spark, "t_phm_mxxq").select(col("MX_ID"), col("SYJX"), col("MXMC"), col("MXJG"), col("JGMS"), col("XXMS"), col("CZJY"), col("ZBJY"), col("JXJY")).as(Encoders.bean(PhmMxxq.class));
        Dataset<TcmsRealDataJoinMxxq> joinAfterDs = hxd1DTcmsRealDataDS.alias("t1").join(mxxqDS.alias("t2"), expr("t1.phm_mc = t2.xxms"), "left").as(Encoders.bean(TcmsRealDataJoinMxxq.class));
        Dataset<Row> rowDataset = joinAfterDs.withColumn("czjy", when(col("phm_lb").equalTo("变流器元件故障报警"), "检查或更换对应模块的脉冲/驱动板、IGBT").otherwise(col("czjy")))
                .withColumn("mx_id", when(col("phm_lb").equalTo("变流器元件故障报警"), "10003").otherwise(col("mx_id")))
                .withColumn("mxjg", when(col("phm_lb").equalTo("变流器元件故障报警"), "元件故障").otherwise(col("mxjg")))
                .withColumn("syjx", when(col("phm_lb").equalTo("变流器元件故障报警"), "HXD1D").otherwise(col("syjx")))
                .withColumn("mxmc", when(col("phm_lb").equalTo("变流器元件故障报警"), "牵引变流器元件故障视情维修模型").otherwise(col("mxmc")))
                .withColumn("xxms", when(col("phm_lb").equalTo("变流器元件故障报警"), col("phm_mc")).otherwise(col("xxms")));
        return rowDataset.as(Encoders.bean(TcmsRealDataJoinMxxq.class));
    }
}